﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMP
{
    public class MusicFile: IMusicFile
    {
        public static readonly string DefaultPath;
        public static readonly string DefaultTitle = "Unknown Title";
        public static readonly string DefaultAlbum = "Unknown Album";
        public static readonly string DefaultArtist = "Unknown Artist";
        public static readonly int DefaultTrack = -1;

        public override string ToString()
        {
            return "MF: " + this.Title;
        }

        public MusicFile() : this(DefaultPath, DefaultTitle, DefaultAlbum, DefaultArtist, DefaultTrack) { }

        public MusicFile(string path, string title, string album, string artist, int track)
        {
            Path = path;
            Title = title;
            Album = album;
            Artist = artist;
            Track = track;
        }

        public MusicFile(string path)
        {
            TagReader id3v2_3 = new ID3V2_3(path);

            if (id3v2_3.IsThisTagType)
            {
                ReadTags(id3v2_3);
            }

            // else for the other types
            // might be able to use reflection?
        }

        private void ReadTags(TagReader reader)
        {
            Title = reader.Title;
            Album = reader.Album;
            Artist = reader.Artist;
            Track = reader.Track;
        }

        #region IMusicFile Members

        public string Path { get; protected set; }

        public string Title { get; protected set; }

        public string Album { get; protected set; }

        public string Artist { get; protected set; }

        public int Track { get; protected set; }

        #endregion
    }
}
